package exercise.day07;

import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {
        //1.录入成绩
//        double[] socer = cal();
//        for (double f : socer) {
//            System.out.println(f);
//        }
        //2.计算总分
//        double sum = calTotal(socer);
//        System.out.println("总分："+sum);
        //3.计算平均分
//        double avg = avg(socer);
        //4.输出总分和平均分
//        System.out.println("平均分："+avg);


        double[] socer=cal1();
        double sum=calTotal1(socer);
        System.out.println("总分："+sum);
        double avge=avge(socer);
        System.out.println("平均分："+avge);

    }

    public static double[] cal1(){
        double[] socer=new double[6];
        Scanner scan=new Scanner(System.in);
        for(int i=0;i<socer.length;i++){
            System.out.println("请输入第"+(i+1)+"位评委分数：");
            socer[i]=scan.nextDouble();
        }
        return socer;
    }
    public static double calTotal1(double[] socer){
        double sum=0.0;
        double max=socer[0];
        double min=socer[0];
        for(int i=0;i<socer.length;i++){
            if(max<socer[i]){
                max=socer[i];
            }else if (min>socer[i]){
                min=socer[i];
            }
            sum+=socer[i];
        }
        return sum-max-min;
    }
    public static double avge(double[] socer){
        double avge=calTotal1(socer);
        avge/=socer.length-2;

        return avge;
    }

    public static double[] cal() {
        double[] socer = new double[6];
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < socer.length; i++) {
            System.out.println("请输入第" + (i + 1) + "评委的分数");
            socer[i] = scan.nextDouble();
        }
        return socer;
    }

    public static double calTotal(double[] socer) {
        double sum = 0.0;
        double max = socer[0];
        double min = socer[0];
        for (int i = 0; i < socer.length; i++) {
            sum += socer[i];
            if (max < socer[i]) {
                max = socer[i];
            } else if (min > socer[i]) {
                min = socer[i];
            }

        }
        return sum - max - min;
    }

    public static double avg(double[] socer) {
        double avg = calTotal(socer);
        avg /= socer.length - 2;
        return avg;
    }
}
